package com.xinzhidi.web.equipment.controller;

import com.xinzhidi.common.annotation.Log;
import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.common.core.domain.R;
import com.xinzhidi.common.core.page.TableDataInfo;
import com.xinzhidi.common.enums.BusinessType;
import com.xinzhidi.common.utils.poi.ExcelUtil;
import com.xinzhidi.web.equipment.dto.EquipmentArchivesRestoreAddDto;
import com.xinzhidi.web.equipment.dto.EquipmentArchivesRestoreListDto;
import com.xinzhidi.web.equipment.dto.EquipmentArchivesRestoreUpdDto;
import com.xinzhidi.web.equipment.service.IEquipmentArchivesRestoreService;
import com.xinzhidi.web.equipment.vo.EquipmentArchivesRestoreInfoVo;
import com.xinzhidi.web.equipment.vo.EquipmentArchivesRestoreListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 存档恢复记录Controller
 *
 * @author ruoyi
 * @date 2023-07-21
 */
@RestController
@Api(tags = "存档恢复记录")
@RequestMapping("/equipmentArchivesRestore")
public class EquipmentArchivesRestoreController extends BaseController
{
    @Autowired
    private IEquipmentArchivesRestoreService equipmentArchivesRestoreService;

    @ApiOperation("查询存档恢复记录列表")
    @PreAuthorize("@ss.hasPermi('admin:equipmentArchivesRestore:list')")
    @PostMapping("/listEquipmentArchivesRestore")
    public TableDataInfo<EquipmentArchivesRestoreListVo> listEquipmentArchivesRestore(@Validated @RequestBody EquipmentArchivesRestoreListDto dto)
    {
        startPagePost(dto);
        return equipmentArchivesRestoreService.selectEquipmentArchivesRestoreList(dto);
    }

    @ApiOperation("导出存档恢复记录列表")
    @PreAuthorize("@ss.hasPermi('admin:equipmentArchivesRestore:export')")
    @Log(title = "存档恢复记录", businessType = BusinessType.EXPORT)
    @PostMapping("/exportEquipmentArchivesRestore")
    public void exportEquipmentArchivesRestore(HttpServletResponse response,EquipmentArchivesRestoreListDto dto)
    {
        TableDataInfo<EquipmentArchivesRestoreListVo> list = equipmentArchivesRestoreService.selectEquipmentArchivesRestoreList(dto);
        ExcelUtil<EquipmentArchivesRestoreListVo> util = new ExcelUtil<EquipmentArchivesRestoreListVo>(EquipmentArchivesRestoreListVo.class);
        util.exportExcel(response, list.getRows(), "存档恢复记录数据");
    }

    @ApiOperation("获取存档恢复记录详细信息")
    @PreAuthorize("@ss.hasPermi('admin:equipmentArchivesRestore:query')")
    @GetMapping(value = "/getEquipmentArchivesRestoreById")
    public R<EquipmentArchivesRestoreInfoVo> getEquipmentArchivesRestoreById(@RequestParam("id") Long id)
    {
        return R.ok(equipmentArchivesRestoreService.selectEquipmentArchivesRestoreById(id));
    }

    @ApiOperation("新增存档恢复记录")
    @PreAuthorize("@ss.hasPermi('admin:equipmentArchivesRestore:add')")
    @Log(title = "存档恢复记录", businessType = BusinessType.INSERT)
    @PostMapping("addEquipmentArchivesRestore")
    public AjaxResult addEquipmentArchivesRestore(@Validated @RequestBody EquipmentArchivesRestoreAddDto dto)
    {
        return toAjax(equipmentArchivesRestoreService.insertEquipmentArchivesRestore(dto));
    }

    @ApiOperation("修改存档恢复记录")
    @PreAuthorize("@ss.hasPermi('admin:equipmentArchivesRestore:edit')")
    @Log(title = "存档恢复记录", businessType = BusinessType.UPDATE)
    @PostMapping("editEquipmentArchivesRestore")
    public AjaxResult editEquipmentArchivesRestore(@Validated @RequestBody EquipmentArchivesRestoreUpdDto dto)
    {
        return toAjax(equipmentArchivesRestoreService.updateEquipmentArchivesRestore(dto));
    }

    @ApiOperation("删除存档恢复记录")
    @PreAuthorize("@ss.hasPermi('admin:equipmentArchivesRestore:remove')")
    @Log(title = "存档恢复记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/delEquipmentArchivesRestore")
    public AjaxResult delEquipmentArchivesRestore(@RequestParam Long[] ids)
    {
        return toAjax(equipmentArchivesRestoreService.deleteEquipmentArchivesRestoreByIds(ids));
    }

    @ApiOperation("批量恢复")
    @Log(title = "批量恢复", businessType = BusinessType.DELETE)
	@DeleteMapping("/addRestore")
    public AjaxResult addRestore(@RequestParam Long[] ids)
    {
        return toAjax(equipmentArchivesRestoreService.addRestore(ids));
    }
}
